/*****************************************************************************
 * Copyright (C) Stacy Curl. All rights reserved.                            *
 * ------------------------------------------------------------------------- *
 * The software in this package is published under the terms of the BSD      *
 * style license a copy of which has been included with this distribution in *
 * the LICENSE.txt file.                                                     *
 *****************************************************************************/
package picounit.features.base;

import picounit.features.Feature;

import java.util.Set;

class ClassFeatureDescription<F extends Feature> implements FeatureDescription {
	private final FeatureInstantiator featureInstantiator;
	private final Class<F> featureClass;
	
	public ClassFeatureDescription(FeatureInstantiator featureInstantiator, Class<F> featureClass) {
		this.featureClass = featureClass;
		this.featureInstantiator = featureInstantiator;
	}

	public void insertInto(FeatureRegistry featureRegistry, Set<String> featuresLoaded) {
		try {
			F feature = featureInstantiator.instantiate(featureClass);

			feature.addFeatures(featureRegistry);

			featuresLoaded.add(featureClass.getName());
		}
		catch (Exception exception) {
			exception.printStackTrace();
		}
	}
}